package com.sanjiahantang.shopping.uilibrary.views;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.os.Build;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ImageView;

import com.sanjiahantang.shopping.uilibrary.R;
import com.squareup.picasso.Picasso;

/**
 * Created by zy on 2017/10/10.
 */

@SuppressLint("AppCompatCustomView")
public class RecycleImageView extends ImageView {
    public RecycleImageView(Context context) {
        super(context);
    }

    public RecycleImageView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public RecycleImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public RecycleImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        try {
            super.onDraw(canvas);
        } catch (Exception e) {
            Picasso.with(getContext()).load((String) getTag(R.id.decode)).into(this);
            Log.e("RecycleImage",(String) getTag(R.id.decode));
        }
    }

}
